public class No024 {
    /**
     * 输入一个链表，反转链表后，输出新链表的表头。
     */
    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

    // pre -> head -> pNext
    public ListNode ReverseList(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode pNext;
        ListNode pPre = null;
        while (head != null) {
            pNext = head.next;
            head.next = pPre;

            pPre = head;
            head = pNext;
        }
        return pPre;
    }
}
